package com.penghaonan.appframework.utils.threadpool;

import com.penghaonan.appframework.utils.Logger;

public abstract class ThreadPoolTask implements Runnable {
    private boolean cancelled;
    private Object key;
    private String name = "unknown";

    public ThreadPoolTask() {
    }

    public ThreadPoolTask(String name) {
        this.name = name;
    }

    protected abstract void doInBackground();

    public void setKey(Object keyObj) {
        this.key = keyObj;
    }

    public Object getKey() {
        Object obj = this.key;
        return obj == null ? this : obj;
    }

    public void cancel() {
        this.cancelled = true;
    }

    /* access modifiers changed from: protected */
    public boolean isCancelled() {
        return this.cancelled;
    }

    public final void run() {
        long startTime = System.currentTimeMillis();
        doInBackground();
        long timeSpent = System.currentTimeMillis() - startTime;
        if (timeSpent > 500) {
            Logger.e(taskName() + " spent time:" + timeSpent);
        }
//        Logger.i(taskName() + " spent time:" + timeSpent);
    }

    private String taskName() {
        return "task(" + name + ")";
    }
}
